*** Settings ***
Documentation    用户登录及发布话题
Library     SeleniumLibrary

*** Variables ***
${main_url}     http://39.107.96.138:3000/

*** Keywords ***
打开谷歌浏览器
    [Arguments]    ${url}
    Open Browser      ${url}     Chrome
    Maximize Browser Window

设置等待时间
    Set Selenium Implicit Wait    10
    Set Selenium Speed    0.3

关闭浏览器
    Close Window

用户登录
    [Arguments]   ${username}    ${password}
    Click Element   //a[@href="/signin"]
    Input Text    //*[@id="name"]     ${username}
    Input Text    //*[@id="pass"]    ${password}
    Click Element    //input[@type="submit"]
    Element Text Should Be    //span[@class="user_name"]/a[@class="dark"]    ${username}

用户发布话题
    [Arguments]    ${topic}
    Click Element    //*[@id="create_topic_btn"]/span
    Click Element    //*[@id="tab-value"]/option[3]
    Input Text    //textarea[@id="title"]    ${topic}
 #   Set Focus To Element    xpath://div[@class="CodeMirror-scroll"]
    Click Element    //pre
    Press Keys      //pre     ${topic}
    Press Keys      //pre     COMMAND+a
    Click Element      //a[@class="eicon-bold"]
    Click Element    //input[@value="提交"]
    Element Text Should Be    //span[@class="topic_full_title"]    ${topic}
    ${mitty_topic_url}     Log Location
    [Return]    ${mitty_topic_url}

用户删除话题
    [Arguments]    ${mitty_topic_url}
    Click Element    //i[@title="删除"]
    Handle Alert    action=DISMISS
    Click Element    //i[@title="删除"]
    Handle Alert
    Go To    ${mitty_topic_url}
    Element Text Should Be  //strong    此话题不存在或已被删除。

*** *** Test Cases ***
用户登录并发布话题
    打开谷歌浏览器    ${main_url}
    设置等待时间
    用户登录    mitty    123456
    ${mitty_topic_url}    用户发布话题    Mitty_question
    关闭浏览器

用户删除话题
    打开谷歌浏览器    ${main_url}
    用户登录    mitty    123456
    Go to     ${mitty_topic_url}
    用户删除话题    ${mitty_topic_url}
